#!/bin/bash
#SBATCH -J GROMACS-DCU
#SBATCH -p wzhdnormal
#SBATCH -N 1
#SBATCH --ntasks-per-node=4
#SBATCH --cpus-per-task=8
#SBATCH --gres=dcu:4
#SBATCH -o log/one_submit_%j.loop
#SBATCH -e log/one_submit_%j.loop

source ~/.bashrc
#source /work/home/aixplorerbio_wz/miniconda3/bin/activate amber
#source /work/home/aixplorerbio_wz/software/gromacs-2020.3/bin/GMXRC

module switch compiler/dtk/21.04
module load apps/Gromacs-DCU2/2020.3-dtk21.04/hpcx-gcc-7.3.1

# 仓库根路径, 根据实际情况填写
PROJECT_HOME=/work/home/aixplorerbio_wz/mmgbsa/debug/md_project

if [ $# != 1 ]; then
    echo "USAGE: $0 $MD_PATH"
    echo " e.g.: $0 test_md/"
    exit 1
fi

if [ ! -f "$PROJECT_HOME/work_dir/one_bind.sh" ]; then
    echo "File \"$PROJECT_HOME/work_dir/one_bind.sh\" not exists, 请设置PROJECT_HOME变量"
    exit -1
fi

pwd=$(pwd)
WORK_PATH=$(cd $1 && pwd)

cd $WORK_PATH
echo "md=$WORK_PATH project_home=$PROJECT_HOME"

srun hostname | sort | uniq | awk '{printf "%s\n",$1}' >hostfile
((num_procs = $SLURM_JOB_NUM_NODES * 4))

mpirun -hostfile hostfile -np 4 -N 4 --bind-to none $PROJECT_HOME/work_dir/one_bind.sh
